package cn.com.spbun.nddd.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;

import cn.com.spbun.common.FileUtil;

/**
 * @author NOLY DAKE
 *
 */
public class AboutDialog extends JDialog {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -7611156275732847279L;

    public static void main(String[] args) {
        new AboutDialog(null).setVisible(true);
    }

    private JFrame frame = null;

    public AboutDialog(JFrame frame) {
        super(frame, true);

        this.frame = frame;

        initGUI();
    }

    private void initGUI() {

        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("关于");

        JTextPane jtp = new JTextPane();
        jtp.setContentType("text/html");
        jtp.setEditable(false);

        jtp.setText(FileUtil.read2String(new File(FileUtil.getInstallPath(), "readme.html"), "UTF-8"));
        JScrollPane jsp = new JScrollPane(jtp);

        getContentPane().add(jsp, BorderLayout.CENTER);

        JButton button = new JButton("我知道了");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                AboutDialog.this.dispose();
            }
        });
        this.add(button, BorderLayout.SOUTH);

        this.setSize(new Dimension(600, 600));
        this.setLocationRelativeTo(frame);
    }
}
